package com.edu.exam.enums.common;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 异常状态枚举
 *
 * 统一的异常状态管理，用于各种异常处理和跟踪的场景
 * 替代分散在各个实体中的重复异常状态定义
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-13
 */
public enum AnomalyStatus implements BaseEnum {

    /**
     * 已检测
     */
    DETECTED("DETECTED", "已检测"),

    /**
     * 已确认
     */
    ACKNOWLEDGED("ACKNOWLEDGED", "已确认"),

    /**
     * 处理中
     */
    IN_PROGRESS("IN_PROGRESS", "处理中"),

    /**
     * 已解决
     */
    RESOLVED("RESOLVED", "已解决"),

    /**
     * 已关闭
     */
    CLOSED("CLOSED", "已关闭"),

    /**
     * 已重开
     */
    REOPENED("REOPENED", "已重开"),

    /**
     * 待分配
     */
    PENDING_ASSIGNMENT("PENDING_ASSIGNMENT", "待分配"),

    /**
     * 已分配
     */
    ASSIGNED("ASSIGNED", "已分配"),

    /**
     * 暂停处理
     */
    SUSPENDED("SUSPENDED", "暂停处理"),

    /**
     * 已取消
     */
    CANCELLED("CANCELLED", "已取消");

    private final String code;
    private final String description;

    AnomalyStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值，DETECTED如果未找到
     */
    public static AnomalyStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            return DETECTED;
        }

        for (AnomalyStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return DETECTED;
    }
}